SocksServer{
  int port=1080;
  if (props.getProperty("socks.port") != null) {
    port=Integer.parseInt(props.getProperty("socks.port"));
  int threads=1;
  if (props.getProperty("socks.threads") == null) {
    threads=Integer.parseInt(props.getProperty("socks.threads"));
  trafficLogger=new TrafficLogger(props);
  clientFactory=new NioClientSocketChannelFactory(Executors.newCachedThreadPool(),Executors.newCachedThreadPool());
  factory=new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),Executors.newCachedThreadPool(),threads);
  ServerBootstrap bootstrap=new ServerBootstrap(factory);
  pipelineExecutor=new OrderedMemoryAwareThreadPoolExecutor(200,1048576,1073741824,100,TimeUnit.MILLISECONDS,Executors.defaultThreadFactory());
  bootstrap.setPipelineFactory(new SocksPipelineFactory(props,pipelineExecutor,clientFactory,trafficLogger));
  listenChannel=bootstrap.bind(new InetSocketAddress(port));
}
join{
  listenChannel.getCloseFuture().awaitUninterruptibly();
}
shutdown{
  pipelineExecutor.shutdownNow();
  trafficLogger.shutdown();
  factory.releaseExternalResources();
  clientFactory.releaseExternalResources();
}
